using System;
using System.ComponentModel.DataAnnotations;

namespace Abhar.web.src
{
    using System.Web;
    using System.Configuration;

    partial class DatabaseContext
    {
        public static DatabaseContext Current
        {
            get
            {
                var httpContext = HttpContext.Current;
                if (httpContext == null)
                    return null;

                var context = httpContext.Items["database"] as DatabaseContext;
                if(context == null)
                {
                    context = new DatabaseContext(ConfigurationManager.ConnectionStrings[0].ConnectionString);
                    httpContext.Items["database"] = context;
                }
                return context;
            }
        }
    }

    [MetadataType(typeof(NewsMetadata))]
    partial  class News
    {
        partial void OnCreated()
        {
            this.CreationDate = DateTime.Now;
            this.LastUpdatedDate = DateTime.Now;
        }
    }

    public class NewsMetadata 
    {
        [UIHint("FileUpload")]
        public object ImgUrl { set; get; }

        [ScaffoldColumn(false)]
        public object CreationDate { set; get; }

        [ScaffoldColumn(false)]
        public object LastUpdatedDate { set; get; }
    }
}
